﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Common;
using Core;

namespace WinClient
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void btnBuild_Click(object sender, EventArgs e)
        {
            string providerName = DataConnection.TestSQLSettings.ProviderName;
            string connectionString = DataConnection.TestSQLSettings.ConnectionString;

            var tableSelector = new FormTableSelector(providerName, connectionString);
            tableSelector.ShowDialog();

            var  builders = new List<Builder>();
            for (int i = 0; i < tableSelector.SelectedTables.Count; i++)
            {
                SimpleTableInfo table = tableSelector.SelectedTables[i];
                builders.Add(new Builder(providerName
                                         , connectionString
                                         , string.Concat(table.Table_Schema,".",table.Name)
                                         , new string[] { null, table.Table_Schema, table.Name }));
            }
            //Builder[] builders = new Builder[]{
            //    new Builder(providerName, connectionString, "[dbo].[DatabaseLog]",new string[]{null,"dbo","DatabaseLog"}),
            //    new Builder(providerName, connectionString, "[Purchasing].[vVendor]",new string[]{null,"Purchasing","vVendor"})
            //};

            var templates = new string[]{
                                            System.IO.Path.Combine(System.IO.Path.Combine(Application.StartupPath,"Template"),"Dao.st"),
                                            System.IO.Path.Combine(System.IO.Path.Combine(Application.StartupPath,"Template"),"Entity.st")
                                        };

            var builderMicro = new BuilderMicro(templates, builders.ToArray());
            this.textBox1.AppendText(
                builderMicro.Build()
                );
            builderMicro.Build("C:\\1");
        }
    }
}